WARNING: This program has a bug, which means we need to fix it! Empty if statements cannot run!
RULE:If statements must have code indented inside that runs if the test statement is true.
Click Run and read the error message.
Debug this program so that the sprite says "It will be an adventure!" if the user answers yes.
Use a Say command and change the string to complete the if statement.
To navigate the page using the TAB key, first press ESC to exit the code editor.
stage.set_background("space")
sprite = codesters.Sprite("astronaut2", 0, -150)
choice = sprite.ask("Do you want to visit Mars?")
choice = choice.lower()
if choice == "yes":
# add your code here
elif choice == "no":
# add your code here
sprite.say("OK, have fun on earth!")
else:
sprite.say("I don't speak human, actually!")
t = codesters.Teacher()
ifs = t.find_block('if')
elifs = t.find_block('elif')
elses = t.find_text('else')
says = t.get_parameters_for_function('say')
try:
tval1 = ifs[0][1]
tval2 = ifs[0][0]
except:
tval1 = "DNE"
tval2 = "DNE"
try:
say_cmd = t.find_text('sprite.say')
say_line = say_cmd[0][0]
tval3 = t.get_indent_at_line(say_line)
except:
tval3 = "DNE"
try:
tval4 = choice
except:
tval4 = "DNE"
try:
tval5 = says[0][0]
except:
tval5 = "DNE"
t1 = TestObjective()
t1.add_success("if choice == " in tval1, "Great job debugging the program!")
t1.add_failure(tval4 == "DNE", "Did you delete your ask command?")
t1.add_failure(tval1 == "DNE" or tval1 == [] or tval2 == "DNE" or tval2 == [], "Did you delete the if statement?")
t2 = TestObjective()
t2.add_success("adventure" in tval5, "Great job debugging the program!")
t2.add_failure(tval5 == "DNE", "Did you add a Say command?")
t2.add_failure("sprite" in tval5, "Did you change the string in .say()?")
t2.add_failure("adventure" not in tval5, "Did you change the string in .say()?")
t3 = TestObjective()
t3.add_success(tval3 == 4, "Great job!")
t3.add_failure(tval3 == 0, "Did you put the say command inside the if statement?")
t3.add_failure(tval3 > 4, "I think you indented your say command too far.")
t3.add_failure(tval3 == "DNE", "Did you add a say command in the if statement?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.